package nc.bs.mmpac.sumpickm.rule;

import nc.impl.pubapp.pattern.rule.IRule;
import nc.util.mmf.framework.base.MMValueCheck;
import nc.vo.mmpac.sumpickm.consts.SumPickmLangConst;
import nc.vo.mmpac.sumpickm.entity.AggSumPickmVO;
import nc.vo.mmpac.sumpickm.entity.SumPickmSumVO;
import nc.vo.pub.VOStatus;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

public class SumPickmCheckSumNotNullRule implements IRule<AggSumPickmVO> {

    @Override
    public void process(AggSumPickmVO[] vos) {
        if (MMValueCheck.isEmpty(vos)) {
            return;
        }

        for (AggSumPickmVO vo : vos) {
            if (vo.getParentVO().getCsumpickmtype() == null) {
                ExceptionUtils.wrappBusinessException(SumPickmLangConst.getTrantypeSaveFailedMsg());
            }
            SumPickmSumVO[] sums = (SumPickmSumVO[]) vo.getChildren(SumPickmSumVO.class);
            if (MMValueCheck.isEmpty(sums)) {
                ExceptionUtils.wrappBusinessException(SumPickmLangConst.getNoneSumSaveFailedMsg());

            }
            int count = 0;
            for (SumPickmSumVO sum : sums) {
                if (sum.getStatus() != VOStatus.DELETED) {
                    count++;
                }
            }
            if (count <= 0) {
                ExceptionUtils.wrappBusinessException(SumPickmLangConst.getNoneSumSaveFailedMsg());
            }

        }

    }

}
